bitkeeper revision 1.1010.1.5 (40dbfee81bMxq2pSAYIoYZMhqQUEtg)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Fri, 25 Jun 2004 10:31:04 +0000 (10:31 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Fri, 25 Jun 2004 10:31:04 +0000 (10:31 +0000)
Fix help message for xm shutdown.
Add long format for xm list.

tools/xenmgr/lib/XendDomainInfo.py
tools/xenmgr/lib/xm/create.py
tools/xenmgr/lib/xm/main.py
tools/xenmgr/lib/xm/opts.py
tools/xenmgr/lib/xm/shutdown.py

index 0dfd1a71ee8986f35d682c4d5d19ad246cc0187e..1f44f026a4b8c3db7456c3df5f71be4579c18ea8 100644 (file)
@@ -364,6 +364,7 @@ class XendDomainInfo:
         """Update with  info from xc.domain_getinfo().
         """
         self.info = info
+        self.memory = self.info['mem_kb'] / 1024
 
     def __str__(self):
         s = "domain"
index 3d4165d1f2a16fea026808db0404be77628217d7..d0bfa0859c61df0113fb304106a49895df76c30c 100644 (file)
@@ -28,7 +28,7 @@ gopts.opt('path', val='PATH',
          use="Search path for default scripts.")
 
 gopts.opt('defaults', short='f', val='FILE',
-         fn=set_value, default='defaults',
+         fn=set_value, default='xmdefaults',
          use="Use the given default script.")
 
 gopts.opt('config', short='F', val='FILE',
index 09b658d8504cb86546e2a80042ed41f0ceeab41a..673cccd9fabc488d30958d3a6bcce4d28f8a084d 100644 (file)
@@ -4,6 +4,7 @@
 import os
 import os.path
 import sys
+from getopt import getopt
 
 from xenmgr import PrettyPrint
 from xenmgr import sxp
@@ -196,20 +197,41 @@ class ProgList(Prog):
     name = "list"
     info = """List info about domains."""
 
+    short_options = 'l'
+    long_options = ['long']
+
     def help(self, args):
         if help:
-            print args[0], '[DOM...]'
+            print args[0], '[options] [DOM...]'
             print """\nGet information about domains.
-            Either all domains or the domains given."""
+            Either all domains or the domains given.
+
+            -l, --long   Get more detailed information.
+            """
             return
         
     def main(self, args):
-        n = len(args)
-        if n == 1:
-            doms = server.xend_domains()
+        use_long = 0
+        (options, params) = getopt(args[1:],
+                                   self.short_options,
+                                   self.long_options)
+        n = len(params)
+        for (k, v) in options:
+            if k in ['-l', '--long']:
+                use_long = 1
+                
+        if n == 0:
+            doms = map(int, server.xend_domains())
+            doms.sort()
         else:
-            doms = map(int, args[1:])
-        doms.sort()
+            doms = map(int, params)
+            
+        if use_long:
+            self.long_list(doms)
+        else:
+            self.brief_list(doms)
+
+    def brief_list(self, doms):
         print 'Dom  Name             Mem(MB)  CPU  State  Time(s)'
         for dom in doms:
             info = server.xend_domain(dom)
@@ -222,6 +244,12 @@ class ProgList(Prog):
             d['cpu_time'] = float(sxp.child_value(info, 'cpu_time', '0'))
             print ("%(dom)-4d %(name)-16s %(mem)7d  %(cpu)3d  %(state)5s  %(cpu_time)7.1f" % d)
 
+    def long_list(self, doms):
+        for dom in doms:
+            info = server.xend_domain(dom)
+            print '\nDomain %d' % dom
+            PrettyPrint.prettyprint(info)
+
 xm.prog(ProgList)
 
 class ProgDestroy(Prog):
@@ -246,8 +274,7 @@ class ProgShutdown(Prog):
     info = """Shutdown a domain."""
 
     def help(self, args):
-        print args[0], 'DOM'
-        print '\nSignal domain DOM to shutdown.'
+        shutdown.main([args[0], '-h'])
     
     def main(self, args):
         shutdown.main(args)
index b2cb2c7463398640fc226222c7b74776c0572c83..5b9515215dd3607d65f7cad1f9c8c280e09b074e 100644 (file)
@@ -273,7 +273,7 @@ class Opts:
                 self.load(p)
                 break
         else:
-            self.err("Cannot open defaults file %s" % self.defaults)
+            self.err("Cannot open defaults file %s" % self.vals.defaults)
 
     def load(self, defaults, help=0):
         """Load a defaults file. Local variables in the file
index 50d98bec5e0b86c4a7d78b460414c9b19a64f60b..2c7831876b4431916ad17c752d1512a841aca061 100644 (file)
@@ -50,7 +50,7 @@ def shutdown(opts, doms, wait):
         opts.info("All domains terminated")
 
 def main_all(opts, args):
-    shutdown(opts, None, opts.wait)
+    shutdown(opts, None, opts.vals.wait)
 
 def main_dom(opts, args):
     if len(args) < 1: opts.err('Missing domain')
@@ -59,7 +59,7 @@ def main_dom(opts, args):
         domid = int(dom)
     except:
         opts.err('Invalid domain: ' + dom)
-    shutdown(opts, [ domid ], opts.wait)
+    shutdown(opts, [ domid ], opts.vals.wait)
     
 def main(argv):
     opts = gopts
@@ -68,7 +68,7 @@ def main(argv):
         opts.usage()
         return
     print 'shutdown.main>', len(args), args
-    if opts.all:
+    if opts.vals.all:
         main_all(opts, args)
     else:
         main_dom(opts, args)